using System;
using System.Threading;
using System.Threading.Tasks;
using Phoenix.ActionResults;

namespace Phoenix.Framework
{
    public class ReflectedActionDescriptor : ActionDescriptorBase
    {
        public ReflectedActionDescriptor(
            MethodDescriptor methodDescriptor, 
            IControllerDescriptor controllerDescriptor) 
            : base(methodDescriptor, controllerDescriptor)
        {
        }

        public override Task<ActionResult> Execute(IController controller, ControllerActionContext controllerActionContext)
        {
            return Task.Factory.StartNew(
                () => Invoke<ActionResult>(controller, controllerActionContext), CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
        }
    }
}